package util

import (
	"fmt"
	syslog "log"
	"os"
	"time"
)

type Logger struct {
	logger *syslog.Logger
}

var MyLogger Logger
var LogFile *os.File

func init() {
	os.MkdirAll("./medialog", 0777)
	fileName := time.Now().Format("medialog/2006-01-02 15-04-05.txt")
	LogFile, err := os.Create(fileName)

	if err != nil {
		syslog.Fatalln("open file error")
	}
	MyLogger.logger = syslog.New(LogFile, "[Info]", syslog.Llongfile)
}

func (l Logger) Printf(format string, v ...interface{}) {
	l.logger.Printf(format, v...)
}

func (l Logger) PrintfWithConsole(format string, v ...interface{}) {
	l.Printf(format, v...)
	fmt.Printf(format, v...)
}

func (l Logger) Println(v ...interface{}) {
	l.logger.Println(v...)
}

func (l Logger) PrintlnWithConsole(v ...interface{}) {
	l.Println(v...)
	fmt.Println(v...)
}
